<?php
session_start();
/**
 * template name: Temp Update ProFile
 * description: impletement drawing of user
 * @author Tham NN  date 26/12/14
 */
if ($_SESSION['userlogin'] == "") {
    wp_redirect(get_site_url() . "/login"); //redirect login
}
$id_user = $_SESSION['userlogin']['ID'];
if (isset($_POST['bt_register'])) {

    $user = new User();
    $data['id_user'] = $id_user;
    $data['first_name'] = $_REQUEST['txt_name'];
    $data['location'] = $_REQUEST['txt_location'];
    $data['last_name'] = $_REQUEST['txt_lastname'];
    $data['password'] = $_REQUEST['txt_password'];
    $data['username'] = $_REQUEST['txt_username2'];
    $data['email'] = $_REQUEST['txt_email2'];
    $data['city'] = $_REQUEST['txt_city'];
    $data['ponit_add'] = $_REQUEST['ponit_add'];
    $data['state'] = $_POST['state'];

    $data['country'] = $_POST['select_country'];
    $data['postcode'] = $_POST['txt_postcode'];
    $data['website'] = $_POST['txt_website'];
    $data['phone_number'] = $_POST['txt_phonenumber'];
    $user->edit_user($data);
    //$user->add_user($data);
    $suscessful = 1;
    ?>
    <div class="modal fade" id="updatepro-sucess" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Update Success</h4>
                </div>
                <div class="modal-body">
                    <?php
                    if ($suscessful == 1) {
                        echo 'You update your account successfully.';
                    }
                    ?>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
    <?php
}
$country = new Country;
$user = new User;
$ds_user = $user->get_user_by_userID($id_user);
$id_user = $ds_user[0]->ID;
$first_name = get_user_meta($id_user, 'first_name');
$last_name = get_user_meta($id_user, 'last_name');
$country_name = $ds_user[0]->country;
$state_province = $ds_user[0]->state_province;


get_header();
?>
<div class="content">
    <div class="container">
        <div class="box-main">
            <div class="row">
                <div class="col-md-9">
                    <div class="tab"><a href="#">Home</a> <?php echo $post->post_title ?> </div>
                    <br/>
                    <div class="text-content">
                        <?php /* .Noi dung trang Login . */ ?>


                        <form  method="post" class="frm_register" >

                            <?php
                            // TH user_type la HOme Builder va Contractor
                            $type_user = $_SESSION['userlogin']['type_user'];
                            ?>
                            <input type="hidden" name="typeuser" id="typeuser" value="<?php echo $type_user ?>" />

                            <p>
                                <label>First Name</label>
                                <input type="text"  id="txt_name" value="<?php echo $first_name[0]; ?>" name="txt_name" />
                            <p id="error_name" class="error_info"  ></p>
                            </p>
                            <p>
                                <label>Last Name</label>
                                <input type="text"  value="<?php echo $last_name[0]; ?>" id="txt_lastname" name="txt_lastname" />

                            <p id="error_lastname"  class="error_info"></p>
                            </p>

                            <p style="display: none">
                                <label>User Name</label>
                                <input type="text"   readonly="readonly" onkeyup="checkusername2();" value="<?php echo $ds_user[0]->user_login; ?>" id="txt_username2" name="txt_username2" />

                            <p id="error_username"  class="error_info"></p>
                            </p>
                            <p>
                                <label>Email Address</label>
                                <input value="<?php echo $ds_user[0]->user_email; ?>" type="text" id="txt_email2" name="txt_email2" />
                            <p id="error_email"  class="error_info"></p>
                            </p>
                            <p>
                                <label>Password</label>
                                <input type="password" id="txt_password" name="txt_password" />
                            <p id="error_passw"  class="error_info"></p>
                            </p>
                            <p>
                                <label>Re-Password:</label>
                                <input type="password" id="txt_repassword"  name="txt_repassword" />
                            <p id="error_repassw"  class="error_info"></p>
                            </p>


                            </p>
                            <p>
                                <label>City</label>
                                <input  onkeyup="check_address_updateprofile();" type="text" value="<?php echo $ds_user[0]->city; ?>"  id="txt_city" name="txt_city" />
                            <p id="error_city"  class="error_info"></p>
                            </p>
                            <p>

                                <label>State</label>
                                <span id="div_get_state"> 
                                    <?php
                                    // echo Country::get_option_state_province_by_id_name_country($country_name,$state_province);
                                    $state_province = $ds_user[0]->state_province;
                                    // echo 'AAAAAAAAAAA'.$state_province;
                                    ?>
                                    <select id="state" name="state" onchange="check_address_updateprofile();">

                                        <option value='' >Select your State</option>

                                        <?php
                                        $ds = $country->get_all_option_state($state_province);
                                        print_r($ds);
                                        ?>
                                    </select>
                                </span>
                            <p id="error_state"  class="error_info"></p>
                            </p>
                            <p>
                                <label>Country</label>
                                <select id="select_country" name ="select_country">
                                    <?php echo $country->get_all_option_country($country_name); ?>
                                </select>
                            </p>
                            <p>
                                <label>Phone Number </label>
                                <input type="text"    id="txt_phonenumber" name="txt_phonenumber" value="<?php echo $ds_user[0]->phone_number ?>" />
                            <p id="error_postcode"  class="error_info"></p>
                            </p> 
                            </p>
                            <p>
                                <label>Postcode </label>
                                <input type="text"    id="txt_postcode" name="txt_postcode" value="<?php echo $ds_user[0]->postcode ?>" />
                            <p id="error_postcode"  class="error_info"></p>
                            </p>
                            <?php //tuan add    ?>     
                            <p>
                                <label>Web site: </label>
                                <input type="text" name="txt_website" value="<?php echo $ds_user[0]->website ?>" />

                            </p>


                            <p>
                                <button onClick="return checkupdateprofile();"  type="submit" name="bt_register"  id="bt_register"  class="button">
                                    Update your account
                                </button>
                            </p>

                        </form>
                    </div>
                </div>
                <?php
                include_once 'right_single.php';
                ?>
            </div>
        </div>
    </div>

</div>
<?php get_footer(); ?>
<script type="text/javascript" language="javascript" src="<?php bloginfo('template_directory') ?>/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" language="javascript" src="<?php bloginfo('template_directory') ?>/js/bootstrap.js"></script>
<script type="text/javascript">
                                jQuery(document).ready(function() {
                                    jQuery("#updatepro-sucess").modal();
                                   
                                });
</script>